<?php declare(strict_types=1);
/**
 * @author      xianganyall <xianganyall@gmail.com>
 * @copyright   2023-2025 owner
 **/

namespace Srv\Libs\ConfModel;

use Srv\Libs\Frame\Conf;

final class NetworkConfGroup extends ConfAbstract
{
    private array $NetworkConfGroupNameList                 = [];       // NetworkConf List groupName

    /**
     * @return array
     * getGroupNameList
     */
    public function getGroupNameList():array
    {
        $NetworkConfList            = [];
        $groupNameList              = Conf::getGroupNameList(NetworkConf::PREFIX);
        if(count($groupNameList) < 1) return $NetworkConfList;
        foreach ($groupNameList as $groupName){
            $NetworkConf            = $this->getByGroupName($groupName);
            if($NetworkConf instanceof NetworkConf) $NetworkConfList[$groupName] = $NetworkConf;
        }
        return $NetworkConfList;
    }

    /**
     * @param string $groupName
     * @return NetworkConf|null
     * getByGroupName
     */
    public function getByGroupName(string $groupName):?NetworkConf
    {
        if(strlen($groupName) < 1) return null;
        if(isset($this->NetworkConfGroupNameList[$groupName]) && $this->NetworkConfGroupNameList[$groupName] instanceof NetworkConf) return $this->NetworkConfGroupNameList[$groupName];
        $confData                                   = Conf::getGroupList(NetworkConf::PREFIX.$groupName.'.', false, true);
        if(count($confData) < 1) return null;
        $this->NetworkConfGroupNameList[$groupName] = new NetworkConf($confData, $groupName);
        return $this->NetworkConfGroupNameList[$groupName];
    }
}